
<html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
	body {
		background:#000;
		color: #fff;
	}
    canvas.emscripten {
        border: 0px none;
        margin-left:auto;
        margin-right:auto;
        display:block
    }

    #loadingDiv {
        text-align: center;
        font-family: monospace;
        font-weight: bold;
        font-size: 150%;
    }
</style>
    </head>

    <body>
      <div id="loadingDiv">Loading...</div>
      <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
      <div style="width:200px; margin-left:auto; margin-right:auto">
      </div>



    <script type='text/javascript'>
        var parentDocument = document;

        var Module = {
            onRuntimeInitialized: function() {
                var e = document.getElementById('loadingDiv');
                e.style.visibility = 'hidden';
            },
            setStatus: function(text) {
                var e = document.getElementById('loadingDiv');
                if (text.search("Downloading data...") != -1) {
                    if (text.search(/[\(]/) != -1) {
                        var download_str = text.split("(")[1].split(")")[0];
                        var download_progress = parseInt(download_str.split("/")[0]);
                        var download_total = parseInt(download_str.split("/")[1]);
                        e.innerHTML = "Downloading data... " + Math.round((download_progress / download_total) * 100) + "%";
                    }
                    else {
                        e.innerHTML = text;
                    }
                }
                else {
                    e.innerHTML = text;
                }
            },
            canvas: (function() {
                var canvas = document.getElementById('canvas');
                return canvas;
                })()
        };
    </script>
    <script>

          (function() {
            var memoryInitializer = 'index.wasm';
            if (typeof Module['locateFile'] === 'function') {
              memoryInitializer = Module['locateFile'](memoryInitializer);
            } else if (Module['memoryInitializerPrefixURL']) {
              memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
            }
            var xhr = Module['memoryInitializerRequest'] = new XMLHttpRequest();
            xhr.open('GET', memoryInitializer, true);
            xhr.responseType = 'arraybuffer';
            xhr.send(null);
          })();

          var script = document.createElement('script');
          script.src = "index.js";
          document.body.appendChild(script);

		// iframe-fix.js
		var lastTarget, canvas, body;
		window.onload = function() {
		  body   = document.querySelector('body'),
		  canvas = document.getElementById('canvas');
		  var activateCanvas = function (event) {
			lastTarget = event.target;
			window.focus();
			console.log("Set focus on window");
		  }
		  var preventScroll = function (event) {
			var keyCodes = [ 32, 37, 38, 39, 40 ];
			if (lastTarget != canvas) {
			  return false;
			}
			// console.log('Key pressed: ' + event.keyCode);
			if (keyCodes.includes(event.keyCode)) {
			  event.preventDefault();
			}
		  }
		  var handleMouseDown = function (event) {
			window.focus();
			event.preventDefault();
			event.stopPropagation();
		  }
		  body.addEventListener('keydown', preventScroll, false);
		  body.addEventListener('click', activateCanvas, false);
		  canvas.addEventListener('mousedown', handleMouseDown, false);

		  // Work-around chromium autoplay policy
		  // https://github.com/emscripten-core/emscripten/issues/6511
		  function resumeAudio(e) {
		  if (typeof Module === 'undefined'
			  || typeof Module.SDL2 == 'undefined'
			  || typeof Module.SDL2.audioContext == 'undefined')
			  return;
		  if (Module.SDL2.audioContext.state == 'suspended') {
			  Module.SDL2.audioContext.resume();
		  }
		  if (Module.SDL2.audioContext.state == 'running') {
			  document.getElementById('canvas').removeEventListener('click', resumeAudio);
			  document.removeEventListener('keydown', resumeAudio);
		  }
		  }
		  document.getElementById('canvas').addEventListener('click', resumeAudio);
		  document.addEventListener('keydown', resumeAudio);
		}
</script>

    </body>
</html>

